package com.yc.web.fillter;

import com.google.gson.Gson;
import com.yc.model.JsonModel;

import javax.servlet.Filter;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

/**
 * @author zwei
 * @create 2024-06-16 11:49
 */
public abstract class  BaseFilter implements Filter {
    protected void writeJson(JsonModel jm, HttpServletResponse resp) throws IOException {
        resp.setContentType(("text/json;charset=utf-8"));
        PrintWriter out=resp.getWriter();
        Gson g=new Gson();
        out.println(g.toJson(jm));
        out.flush();
        out.close();
    }
    protected void writeJson(Map map, HttpServletResponse response) throws IOException {
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out=response.getWriter();
        Gson g=new Gson();
        out.println(g.toJson(map));
        out.flush();
        out.close();
    }
}
